package com.nptever.webcamera;

import com.nptever.webcamera.utils.PTZCommond;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author ZhangKai
 */
@RestController
@RequestMapping(IndexController.URL)
public class IndexController {

    @Autowired
    private IndexService indexService;

    public static final String URL = "/";

    @RequestMapping(method = RequestMethod.GET, produces = "application/json")
    public String index() {
        return "Hello Word!";
    }

    /**
     * 获取设备DNS信息
     * @return 返回服务响应的DNS数据报文
     */
    @RequestMapping(value = "/dns", method = RequestMethod.GET, produces = "application/text")
    public String getDNS() {
        return indexService.getDNS();
    }

    /**
     * 获取设备基本信息
     * @return 返回服务响应的设备数据报文
     */
    @RequestMapping(value = "/device/information", method = RequestMethod.GET, produces = "application/text")
    public String getDeviceInformation() {
        return indexService.getDeviceInformation();
    }

    /**
     * 获取设备发现模式
     * @return 返回服务响应的发现模式报文
     */
    @RequestMapping(value = "/device/discovery/mode", method = RequestMethod.GET, produces = "application/text")
    public String getDiscoveryMode() {
        return indexService.getDiscoveryMode();
    }

    /**
     * 获取设备网关信息
     * @return 返回服务响应的网关数据报文
     */
    @RequestMapping(value = "/device/network/gateway", method = RequestMethod.GET, produces = "application/text")
    public String getNetworkDefaultGateway() {
        return indexService.getNetworkDefaultGateway();
    }

    /**
     * 获取设备网络信息
     * @return 返回服务响应的网络数据报文
     */
    @RequestMapping(value = "/device/network/interfaces", method = RequestMethod.GET, produces = "application/text")
    public String getNetworkInterfaces() {
        return indexService.getNetworkInterfaces();
    }

    /**
     * 获取服务地址
     * @return 返回服务地址信息报文
     */
    @RequestMapping(value = "/service", method = RequestMethod.GET, produces = "application/text")
    public String getServices(){
        return indexService.getServices();
    }

    /**
     * 获取设备媒体配置信息
     * @return 返回流媒体配置信息报文
     */
    @RequestMapping(value = "/rts/media/profiles", method = RequestMethod.GET, produces = "application/text")
    public String getRtsMediaProfiles(){
        return indexService.getRtsMediaProfiles();
    }

    /**
     * 获取视频编码配置信息
     * @return 返回配置信息报文
     */
    @RequestMapping(value = "/rts/video/encoder/config", method = RequestMethod.GET, produces = "application/text")
    public String getRtsVideoEncoderConfigurationOptions(){
        return indexService.getRtsVideoEncoderConfigurationOptions();
    }

    /**
     * 设置视频流配置
     * @return 返回信息报文
     */
    @RequestMapping(value = "/rts/set/video/encoder/config", method = RequestMethod.GET, produces = "application/text")
    public String setVideoEncoderConfiguration(){
        return indexService.setVideoEncoderConfiguration();
    }


    /**
     * 获取设备媒体流地址
     * @return 返回流媒体地址信息报文
     */
    @RequestMapping(value = "/rts/stream/url", method = RequestMethod.GET, produces = "application/text")
    public String getRtsStreamUrl(){
        return indexService.getRtsStreamUrl();
    }

    /**
     * 云台控制
     * @param cmd 控制云台命令 {up, down, left, right, stop, zoomin, zoomout}
     * @return 返回控制信息报文
     */
    @RequestMapping(value = "/ptz/control/{cmd}", method = RequestMethod.GET, produces = "application/text")
    public String relativeMove(@PathVariable String cmd){
        return indexService.relativeMove(PTZCommond.valueOf(cmd));
    }
}
